package com.zyg.apart.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyg.apart.mapper.RoleMapper;
import com.zyg.apart.model.Role;
import com.zyg.apart.service.RoleService;
import com.zyg.apart.util.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public int editRole(Role role) {
        role.setRo_update_time(new Date());
        return roleMapper.editRole(role);
    }

    @Override
    public Role getRoleById(Integer id) {
        return roleMapper.getRoleById(id);
    }

    @Override
    public PageInfo<Map<String, Object>> getAllRole(Integer currentPage) {
        PageHelper.startPage(currentPage, Const.pageSize);
        List<Map<String,Object>> list = roleMapper.getAllRole();
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Map<String,Object>> getAllRoleName() {
        return roleMapper.getAllRoleName();
    }
}
